package de.rj.urwalking.util;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.rj.urwalking.R;
import de.rj.urwalking.db.DBExperiment;

/**
 * Straightforward {@link ArrayAdapter} for displaying {@link DBExperiment}s in a list.
 * @author rjj
 *
 */

public class ExperimentsAdapter extends ArrayAdapter<DBExperiment> {

	private Context context;

	public ExperimentsAdapter(Context context, List<DBExperiment> objects) {
		super(context, R.layout.listitem_experiment, objects);
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View listItem = inflater.inflate(R.layout.listitem_experiment, parent, false);

		TextView textViewTitle = (TextView) listItem.findViewById(R.id.titleTextView);
		TextView textViewDescription = (TextView) listItem.findViewById(R.id.descriptionTextView);

		final DBExperiment item = getItem(position);

		textViewTitle.setText(item.getTitle());
		textViewDescription.setText(item.getDescription());

		return listItem;
	}

}
